<!doctype html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <title>showa 测试用前端</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script type="text/javascript" src="./jquery-3.1.1.min.js"></script>
</head>
<body>

<iframe name="targetIfr" style="display:none"></iframe>
<div>2023年5月28日08:52:13</div>
<a href="/xzy/uploadqc/8b75a9a441e14915bc6feaf681043d74.jpg" target="view_window">测试用CSS</a>
<form id="form_dlg_upload" name="form_dlg_upload" action="/xzy/qcFile/upload" method="post" enctype="multipart/form-data" target="targetIfr" onSubmit=" return submitUpload()">
  <div style="padding-top: 20px;padding-left: 20px">
      <div>
          <input type="file" name="file" id="fileUpload" onchange="handleFiles(this.files)">
      </div>

      <div style="margin-top: 10px;width:250px;" align="right">
          <label for="fileRename">文件名：</label>
          <input type="text" id="fileRename" name="fileRename" required>
      </div>

      <div style="margin-top: 10px;width:250px;" align="right">
          <label for="category">类型：</label>
          <input type="text" id="category" name="category" value="指定资料">
      </div>

      <div style="margin-top: 10px;width:250px;" align="right">
          <label for="remark">备注：</label>
          <input type="text" id="remark" name="remark">
      </div>

      <!-- <div style="display: none"> -->
      <div>
          <input type="text" id="parentId" name="parentId">
      </div>

      <div style="margin-top: 10px;width:250px;" align="right">
          <input id="btnSubmit" name="submitbtn" type="submit" value="提交" style="height:28px">
      </div>
  </div>
</form>
<script type="text/javascript">
	// 将选择的文件名赋值到属性 fileRename 控件上
	// ShipCustomsFiles selectUnique(Integer parentId,String filenameRename);
	// shipCustomsFiles/exists
	function handleFiles(files){
	  	if( !files || files.length<=0 ) return;
	    const file = files[0];
	    const fileName = file.name; // 带有扩展名的完整文件名
	    fileNameArray = fileName.split('.');
	    const fileNamePre = fileNameArray[0];
	    const fileNameSuffix = fileNameArray[1];

	    $('#fileRename').val(fileNamePre);


	    // 验证一个报关明细下不可有重名的文件
	    const parentId = document.getElementById("parentId").value;
	    const params = {"parentId": parentId, "filenameRename": fileNamePre};
	    // $.ajax({
      //   type : "POST",
      //   contentType: "application/json;charset=UTF-8",
      //   url : "shipCustomsFiles/exists",
      //   data: JSON.stringify(params),
      //   success : function(res) {
      //   	if(res && res.data){
      //   		// 存在重名文件
      //   	}
      //   },
      //   error: function(err){

      //   }
      // })
	}

  function fileDuplicate(){
    console.log('文件上传后端发现有重名！');
    alert('文件上传后端发现有重名！');
  }


	// 提交表单按钮触发的事件
	function submitUpload(){
		// 有权限执行则禁用提交按钮，防止多次操作
		document.form_dlg_upload.submitbtn.disabled = true;
	}

	function afterUpload(){
		//console.log('上传完毕！');
    alert('上传完毕！');
	}
</script>
</body>